<template>
  <div class="login-box" style="margin: 200px auto 0;">
    <!-- /.login-logo -->
    <div class="card">
      <div class="card-body login-card-body">
        <p class="login-box-msg">尚硅谷广告管理系统</p>

        <form name="loginForm">
          <div class="input-group mb-3">
            <input type="text" name="adminName" class="form-control" placeholder="请输入管理员账号" v-model="adminName">
            <div class="input-group-append">
              <div class="input-group-text">
                <span class="fas fa-user"></span>
              </div>
            </div>
          </div>
          <div class="input-group mb-3">
            <input name="passWord" type="password" class="form-control" placeholder="请输入管理员密码" v-model="passWord">
            <div class="input-group-append">
              <div class="input-group-text">
                <span class="fas fa-lock"></span>
              </div>
            </div>
          </div>
          <div class="row">
            <!-- /.col -->
            <div class="col-12">
              <button type="submit" name="loginBtn" class="btn btn-primary btn-block" @click.prevent="login"
                @keyup.enter="login">登陆</button>
            </div>
            <!-- /.col -->
          </div>
        </form>

      </div>
      <!-- /.login-card-body -->
    </div>
  </div>

</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      adminName: '',
      passWord: ''
    }
  },
  methods: {
    async login() {
      let result = await this.$store.dispatch('requestLogin', { adminName: this.adminName, passWord: this.passWord })
      console.log(result);
      //登陆成功存入token
      if (result.code === 200) {
        localStorage.setItem('token', result.data.token)
        //跳转路游
        this.$router.push({ path: '/Adv' })
      } else {
        alert(result.message)
      }
    }
  },
}
</script>

<style lang="scss" scoped>
</style>